Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cw-context): encoding, decoding and iteration of ConsensusState heights #1176

Merged
merged 19 commits into from
Apr 22, 2024

Conversation

rnbguy
Copy link
Member

@rnbguy rnbguy commented Apr 19, 2024

Closes: #1175

This PR also replaces string formatting and parsing with protobuf encoding and decoding.

Description


PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests.
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).
  • Tagged one reviewer who will be the one responsible for shepherding this PR.

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

@rnbguy rnbguy marked this pull request as ready for review April 19, 2024 14:13
Copy link

codecov bot commented Apr 19, 2024

Codecov Report

Attention: Patch coverage is 51.19048% with 41 lines in your changes are missing coverage. Please review.

Project coverage is 64.35%. Comparing base (d5e3887) to head (6dc68cf).
Report is 1 commits behind head on main.

Files Patch % Lines
ibc-clients/cw-context/src/context/mod.rs 49.29% 36 Missing ⚠️
ibc-clients/cw-context/src/context/client_ctx.rs 61.53% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1176      +/-   ##
==========================================
- Coverage   64.39%   64.35%   -0.04%     
==========================================
  Files         230      229       -1     
  Lines       22053    22081      +28     
==========================================
+ Hits        14201    14211      +10     
- Misses       7852     7870      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rnbguy rnbguy requested a review from romac April 19, 2024 14:13
@rnbguy rnbguy changed the title fix(wasm08): ConsensusState height iteration, encoding and decoding fix(wasm08): encoding, decoding and iteration of ConsensusState heights Apr 19, 2024
@romac
Copy link
Member

romac commented Apr 19, 2024

Looks like this fixed CI on informalsystems/hermes#3943, not seeing the error anymore even with super short trusting period 🚀

@rnbguy rnbguy changed the title fix(wasm08): encoding, decoding and iteration of ConsensusState heights fix(cw-context): encoding, decoding and iteration of ConsensusState heights Apr 19, 2024
@rnbguy rnbguy requested a review from Farhad-Shabani April 19, 2024 16:28
Comment on lines 1 to 4
- [ibc-clients/cw-context] Fix `ConsensusState` height iteration.
([\#1175](https://github.com/cosmos/ibc-rs/issues/1175))
- [ibc-clients/cw-context] Encode and decode `ConsensusState` heights using
Protobuf. ([\#1176](https://github.com/cosmos/ibc-rs/pull/1176))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this crate has recently been added (Not present in any versions yet), not sure if we should reflect this fix in the changelog.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I didn't know this convention. Removed.

7a10782

Copy link
Member

@Farhad-Shabani Farhad-Shabani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for handling this, @rnbguy! I left a few comments. It would be great if we could reproduce the issue with a unit test, but let's put that off for now. Otherwise, everything looks good.

@Farhad-Shabani Farhad-Shabani added this to the 0.52.0 milestone Apr 19, 2024
Comment on lines +27 to +28
pub const CONSENSUS_STATE_HEIGHT_MAP: Map<'_, (u64, u64), Empty> =
Map::new(ITERATE_CONSENSUS_STATE_PREFIX);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started using this for a better interface. I am curious - if anything breaks if I do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. We should be good as long as the key produced by the Map matches the iteration_key() (?)
Specifically, we only need to use the iteration_key here. (Connected to your question below)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized in the old implementation, we should have used this range_with_prefix from cw-storage-plus. Note the trick for None and exclusive or inclusive cases in calc_start_bound and calc_end_bound.

Since this brings cw-storage-plus dependency anyway, it's best to use their storage abstractions, built on top of these low-level functions.

Comment on lines 230 to 236
for (rev_number, rev_height) in iterator {
let height = Height::new(rev_number, rev_height)?;

for (key, height) in iterator {
metadata.push(GenesisMetadata { key, value: height });
metadata.push(GenesisMetadata {
key: iteration_key(rev_number, rev_height),
value: height.encode_vec(),
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of passing Height here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the why, haven’t had a chance yet to explore where/how this GenesisMetaData gonna be used. But the implementation mirrors ibc-go.

@rnbguy rnbguy force-pushed the rano/fix/wasm08-height-iteration branch from fd7b3db to 6dc68cf Compare April 21, 2024 08:47
@rnbguy
Copy link
Member Author

rnbguy commented Apr 21, 2024

I will merge this after confirming the latest changes on the Hermes PR 🎉

@rnbguy
Copy link
Member Author

rnbguy commented Apr 22, 2024

Tested on personal fork of informalsystems/hermes using workflow artifact from latest commit. Merging it 🚀

Note: once hermes is released with wasm client support. basecoin-rs should have an e2e test for wasm clients.

@rnbguy rnbguy added this pull request to the merge queue Apr 22, 2024
Merged via the queue into main with commit d0f7cc4 Apr 22, 2024
20 checks passed
@rnbguy rnbguy deleted the rano/fix/wasm08-height-iteration branch April 22, 2024 10:22
Farhad-Shabani pushed a commit that referenced this pull request Sep 9, 2024
… heights (#1176)

* only consider ITERATE_CONSENSUS_STATE_PREFIX keys

* use proto codec

* refactor with updated parse_height type sig

* encode and decode height funcs

* fix clippy

* rm redundant type annotation

* add changelog entry

* correct link on changelog

* rm changelog entry

* handle missing case

* use cw_storage_plus::Map

* store or delete height keys at cw_storage_plus::Map

* use cw_storage_plus::Map range or keys

* rm redundant encode_height and decode_height

* add comment

* use imports

* cargo format

* deserialized result must be handled

* update doc string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(cw-context): consensus state heights iteration may consider invalid values
3 participants